package service

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"video_api/basic/config"
	__ "video_api/basic/proot"
	"video_api/handler/model"
)

func VideoAdds(c *gin.Context) {
	var form model.VideoAdd
	// 根据 Content-Type Header 推断使用哪个绑定器。
	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "参数错误",
		})
		return
	}
	videoAdd, err := config.Video.VideoAdd(c, &__.VideoReq{
		Title:    form.Title,
		Type:     form.Type,
		VideoUrl: form.VideoUrl,
		Label:    form.Label,
		Cover:    form.Cover,
		Status:   form.Status,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "添加成功",
		"data": videoAdd.VideoId,
	})
	return
}
